package org.particlethink.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;

import java.util.List;

public class ArrayIntegerTypeHandler extends JsonTypeHandler<List<Integer>> {
    @Override
    List<Integer> jsonToJava(String jsonStr) throws JsonProcessingException {
        if (jsonStr == null) {
            return null;
        }
        ObjectMapper objectMapper = new ObjectMapper();
        CollectionType collectionType = objectMapper.getTypeFactory().constructCollectionType(List.class, Integer.class);
        return objectMapper.readValue(jsonStr, collectionType);
    }
}
